package com.star.message.api;

import com.star.common.core.contract.Page;
import com.star.common.core.contract.R;
import com.star.common.sms.contract.command.SmsTemplateAddCommand;
import com.star.common.sms.contract.command.SmsTemplateUpdateCommand;
import com.star.common.sms.contract.vo.SmsTemplatePageVO;
import com.star.message.biz.SmsTemplateBizService;
import com.star.message.contract.command.SmsTemplateDeleteCommand;
import com.star.message.contract.query.TemplatePageQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信模板控制器
 *
 * @author zhouhengzhe
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "短信模版", description = "短信模版")
@RequestMapping("/message/sms/template")
public class SmsTemplateController {

    private final SmsTemplateBizService smsTemplateBizService;

    /**
     * 查询短信模板
     *
     * @param req 分页查询参数
     */
    @PostMapping("pageSmsTemplate")
    @Operation(summary = "查询短信模板")
    public R<Page<SmsTemplatePageVO>> pageSmsTemplate(@RequestBody TemplatePageQuery req) {
        return R.ok(smsTemplateBizService.pageSmsTemplate(req));
    }


    /**
     * 添加短信模板
     */
    @PostMapping("addSmsTemplate")
    @Operation(summary = "添加短信模板")
    public R<String> addSmsTemplate(@RequestBody @Valid SmsTemplateAddCommand command) {
        return R.ok(smsTemplateBizService.addSmsTemplate(command));
    }

    /**
     * 删除短信模板，会把对应的正在使用中的短信模板删除
     */
    @PostMapping("deleteSmsTemplate")
    @Operation(summary = "删除短信模板")
    public R<Boolean> deleteSmsTemplate(@RequestBody @Valid SmsTemplateDeleteCommand smsTemplateDeleteCommand) {
        return R.ok(smsTemplateBizService.deleteSmsTemplate(smsTemplateDeleteCommand));
    }

    /**
     * 修改短信模板
     */
    @PostMapping("modifyAndReSubmitSmsTemplate")
    @Operation(summary = "修改短信模板")
    public R<Boolean> modifyAndReSubmitSmsTemplate(@RequestBody @Valid SmsTemplateUpdateCommand command) {
        return R.ok(smsTemplateBizService.modifyAndReSubmitSmsTemplate(command));
    }
}
